﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ddb_BT1
{
    public partial class frmDanhSachHDBanHang : DevExpress.XtraEditors.XtraForm
    {
        public frmDanhSachHDBanHang()
        {
            InitializeComponent();
        }

        private void frmDanhSachHDBanHang_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = DataProvider.getDataTable("select * from HOADON_BANHANG,KHACHHANG where HOADON_BANHANG.MA_KHACHHANG=KHACHHANG.MAKH");
        }
        public void Lamtuoi()
        {
            gridControl1.DataSource = DataProvider.getDataTable("select * from HOADON_BANHANG,KHACHHANG where HOADON_BANHANG.MA_KHACHHANG=KHACHHANG.MAKH");
        }
        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            frmHoaDonBanHang frm = new frmHoaDonBanHang();
            frm.frm = this;
            frm.Show();
        }

        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            string STT = gridView1.GetFocusedRowCellValue("STT_HOADON_BH").ToString().Trim();
            frmHoaDonBanHang frm = new frmHoaDonBanHang(STT);
            frm.frm = this;
            frm.Show();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string sql = "select * from HOADON_BANHANG,KHACHHANG where HOADON_BANHANG.MA_KHACHHANG=KHACHHANG.MAKH ";
            if (cbbThang.Text != "") sql = sql + string.Format(" and month(ngayban)={0}", cbbThang.Text);
            if (txtNam.Text != "") sql = sql + string.Format(" and  year(ngayban)={0}", txtNam.Text);
            gridControl1.DataSource = DataProvider.getDataTable(sql);
        }

        private void btnBangKeTheoDoiHDBH_Click(object sender, EventArgs e)
        {
            if (txtNam.Text != "" && cbbThang.Text != "")
            {
                DataTable dt = DataProvider.getDataTable(string.Format("select STT_HOADON_BH,NGAYBAN,MAKH,TENKH,MASOTHUE,(select SUM(CHITIET_HOADON_BH.THANHTIEN)as TIENHANG from CHITIET_HOADON_BH where CHITIET_HOADON_BH.STT_HOADON_BH=HOADON_BANHANG.STT_HOADON_BH )as TONGTIENHANG,(select SUM(CHITIET_HOADON_BH.TIENTHUE)as TIENHANG from CHITIET_HOADON_BH where CHITIET_HOADON_BH.STT_HOADON_BH=HOADON_BANHANG.STT_HOADON_BH )as TONGTIENTHUE from HOADON_BANHANG,KHACHHANG where HOADON_BANHANG.MA_KHACHHANG=KHACHHANG.MAKH  and YEAR(NGAYBAN)={0} and MONTH(NGAYBAN)={1} ",txtNam.Text,cbbThang.Text));
                frmReport_HoaDonBH frm = new frmReport_HoaDonBH(dt, string.Format("BẢNG KÊ THEO DÕI HÓA ĐƠN BÁN HÀNG THÁNG {0} NĂM {1}",cbbThang.Text,txtNam.Text));
                frm.Show();
            }
        }


    }
}